package com.moo2u2.android.oaktononthego.crm.dao;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class CustomerTable {

    public static final String KEY_ROWID = "_id";
    public static final String KEY_NAME = "name";
    public static final String KEY_CONTACT = "contact";
    public static final String KEY_PHONE = "phone";
    public static final String KEY_FAX = "fax";
    public static final String KEY_EMAIL = "email";
    public static final String KEY_ADDRESS = "address";
    public static final String KEY_WINS = "wins";
    public static final String KEY_LOSSES = "losses";
    public static final String KEY_DESCRIPTION = "description";
    public static final String KEY_NOTES = "notes";
    public static final String DB_TABLE = "customers";

    private static final String DATABASE_CREATE = "create table " + DB_TABLE
            + "(" + KEY_ROWID + " integer primary key autoincrement, "
            + KEY_CONTACT + " text not null, " + KEY_NAME + " text not null, "
            + KEY_PHONE + " text, " + KEY_FAX + " text, " + KEY_EMAIL
            + " text, " + KEY_ADDRESS + " text, " + KEY_WINS + " integer, "
            + KEY_LOSSES + " integer, " + KEY_DESCRIPTION + " text, "
            + KEY_NOTES + " text);";

    public static void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
    }

    public static void onUpgrade(SQLiteDatabase database, int oldVersion,
            int newVersion) {
        Log.w(CustomerTable.class.getName(), "Upgrading database from version "
                + oldVersion + " to " + newVersion
                + ", which will destroy all old data");
        database.execSQL("DROP TABLE IF EXISTS " + DB_TABLE);
        onCreate(database);
    }
}